home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / ttdbsscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  2.7 KB  |  122 lines

  1. /* Questo e' un rpc.ttdbserver scanner, visto che la modifica dello statd
  2.    scanner in questo caso mi e' costata qualke secondo non me ne prendo il
  3.    merito... trovo assurdo che su rootshell vengano messi scanner di questo
  4.    tipo. L'originale e' lo statd di BiT! In questo scanner ho messo una
  5.    costante di nome RPC_NAME adattando questa a un determinato servizio rpc
  6.    potete creare quanti scanner x rpc volete ... 
  7.    pIGpEN */
  8.  
  9. #include <stdio.h>
  10. #include <netdb.h>
  11. #include <stdlib.h>
  12. #include <signal.h>
  13. #include <rpc/rpc.h>
  14. #include <arpa/inet.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <netinet/ip.h>
  18. #include <rpc/pmap_prot.h>
  19. #include <rpc/pmap_clnt.h>
  20.  
  21. #define ERROR -1
  22. #define RPC_NAME "ttdbserver"
  23.  
  24. void woopy(int s);
  25. void usage(char *s);
  26. void scan(char *i, char *o);
  27.  
  28. int statd(char *host);
  29. unsigned long int res(char *p);
  30.  
  31. void usage(char *s)
  32. {
  33.   printf("rpc.ttdbserver scanner\n");
  34.   printf("Usage: %s <inputfile> <outputfile>\n",s);
  35.   exit(ERROR);
  36. }
  37.  
  38. void main(int argc, char **argv)
  39. {
  40.   if(argc < 3) usage(argv[0]);
  41.   scan(argv[1], argv[2]);
  42. }
  43.  
  44. void scan(char *i, char *o)
  45. {
  46.   FILE *iff, *of;              
  47. char buf[512];
  48.  
  49.   if((iff=fopen(i,"r")) == NULL)
  50.     return;
  51.   while(fgets(buf,512,iff) != NULL)
  52.   {
  53.     if(buf[strlen(buf)-1]=='\n')
  54.       buf[strlen(buf)-1]=0;
  55.       printf("\n%s",buf); /* Modifica per vedere l'host corrente */
  56.     if(statd(buf) && (of=fopen(o,"a")) != NULL) {
  57.       buf[strlen(buf)+1]=0;
  58.       buf[strlen(buf)]='\n';
  59.  
  60.       fputs(buf,of);
  61.       fclose(of);
  62.     }
  63.   }
  64.   fclose(iff);
  65. }
  66.  
  67. void woopy(int s)
  68. {
  69.   return;
  70. }
  71.  
  72. int statd(char *host)
  73. {
  74.   struct sockaddr_in server_addr;
  75.   struct pmaplist *head = NULL;
  76.   int sockett = RPC_ANYSOCK;
  77.   struct timeval minutetimeout;
  78.   register CLIENT *client;
  79.   struct rpcent *rpc;
  80.  
  81.   server_addr.sin_addr.s_addr=res(host);
  82.   server_addr.sin_family=AF_INET;
  83.   server_addr.sin_port = htons(PMAPPORT);
  84.   minutetimeout.tv_sec = 15;
  85.   minutetimeout.tv_usec = 0;       
  86. signal(SIGALRM,woopy);
  87.   alarm(15);
  88.  
  89.   if ((client = clnttcp_create(&server_addr, PMAPPROG,
  90.         PMAPVERS, &sockett, 50, 500)) == NULL) {
  91.     alarm(0);
  92.     signal(SIGALRM,SIG_DFL);
  93.     return 0;
  94.   }
  95.   alarm(0);
  96.   signal(SIGALRM,SIG_DFL);
  97.  
  98.   if (clnt_call(client, PMAPPROC_DUMP, (xdrproc_t) xdr_void, NULL,
  99.         (xdrproc_t) xdr_pmaplist, &head, minutetimeout) != RPC_SUCCESS)
  100.     return 0;
  101.   if (head != NULL)
  102.     for (; head != NULL; head = head->pml_next)
  103.       if((rpc = getrpcbynumber(head->pml_map.pm_prog)))
  104.         if(strcmp(rpc->r_name,RPC_NAME) == 0)
  105.           return 1;
  106.  
  107.   return 0;
  108. }
  109.  
  110. unsigned long int res(char *p)
  111. {
  112.    struct hostent *h;
  113.    unsigned long int rv;
  114.  
  115.    h=gethostbyname(p);
  116.    if(h!=NULL)
  117.      memcpy(&rv,h->h_addr,h->h_length);
  118.    else
  119.      rv=inet_addr(p);
  120.    return rv;
  121. }                                
  122.